module necrophilia.animation.Cache;
import necrophilia.helpers.Callback;

class AnimationCache(Animation, Instance){
	private Animation[char[]] anims;
	alias Callback!(Instance, Animation) Getter;
	private Getter getter;
	
	this(){
		setGetter(&this.dumbReturn);
	}
	
	void setGetter(Instance delegate(Animation) del){
		getter.set(del);
	}
	
	void setGetter(Instance function(Animation) func){
		getter.set(func);
	}
	
	void addAnimation(char[] name, Animation anim){
		assert( (name in anims) is null);
		anims[name.dup]=anim;
	}
	
	bool isCached(char[] name){
		return (name in anims) !is null;
	}
	
	private Instance dumbReturn(Animation anim){
		return new Instance(anim);
	}
		
	Instance get(char[] name){
		assert( (name in anims) !is null);
		//writefln("*********giveing instance of: ",name);
		return getter.call(anims[name]);
	}
}

import std.stdio;